package com.ruoyi.basedata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.BdPurprice;
import com.ruoyi.basedata.service.IBdPurpriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购价Controller
 * 
 * @author ptt
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/settlementCenter/basedata/purprice")
public class BdPurpriceController extends BaseController
{
    @Autowired
    private IBdPurpriceService bdPurpriceService;

    /**
     * 查询采购价列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(BdPurprice bdPurprice)
    {
        startPage();
        List<BdPurprice> list = bdPurpriceService.selectBdPurpriceList(bdPurprice);
        return getDataTable(list);
    }

    /**
     * 导出采购价列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:export')")
    @Log(title = "采购价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdPurprice bdPurprice)
    {
        List<BdPurprice> list = bdPurpriceService.selectBdPurpriceList(bdPurprice);
        ExcelUtil<BdPurprice> util = new ExcelUtil<BdPurprice>(BdPurprice.class);
        util.exportExcel(response, list, "采购价数据");
    }

    /**
     * 获取采购价详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bdPurpriceService.selectBdPurpriceById(id));
    }

    /**
     * 新增采购价
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:add')")
    @Log(title = "采购价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdPurprice bdPurprice)
    {
        return toAjax(bdPurpriceService.insertBdPurprice(bdPurprice));
    }

    /**
     * 修改采购价
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:edit')")
    @Log(title = "采购价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdPurprice bdPurprice)
    {
        return toAjax(bdPurpriceService.updateBdPurprice(bdPurprice));
    }

    /**
     * 删除采购价
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:purprice:remove')")
    @Log(title = "采购价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bdPurpriceService.deleteBdPurpriceByIds(ids));
    }
}
